<?php
  class admin_module_login
  {
    private $util;
    private $content;
    private $parser;
    private $db;
    private $cls;
    private $pq;
    public function __construct(){ 
        require_once("../code/db.class.php");
        require_once("../code/clsCommons.php");
        require_once '../code/clsPriority.php'; 
        require_once '../code/parser.php'; 
        require_once("../code/util.class.php");
        require_once("../code/parser.php");
        $this->util = new util();
        $this->parser = new parser();
        $this->db = new db();
        $this->cls = new clsCommons();
        $this->pq = new cls_Priority();
        $this->parser->init();
    }
    
    public function _login (){
    $lblDisplay="";
    $is_register=0;
        if(($_POST['mod']=='login') )
        {
            //$p_code = strtoupper($_POST['code']);
            $username = trim($_POST['username']);
            $password = trim($_POST['password']);
            $password = $this->cls->encryptpass($password);

            if($this->cls->fnsCheckAlphaNum($username)==false)
                {
                    $is_register = 1;
                    $lblDisplay.= " - USERNAME  must include from a-z,from 0-9.<br>";
                
                }
                if($is_register==1)
                {
                    $lblDisplay = "<strong>Erors: </strong><br>".$lblDisplay;
                }
            
                else
                {
                    $sql = "SELECT A1.username,A1.password,A1.id 
                    FROM admin as A1
                    WHERE A1.username = '$username' AND A1.password = '".md5($password)."'";
                    //echo $sql;
                    $this->db->openconnection();
                    if($this->db->IsRow($sql))
                    {
                        
                        $r = $this->db->Rows($sql);
                        $_SESSION['admin_id'] = $r[0]['id'];
                        $_SESSION["admin_username"] = $r[0]['username'];
                        header("Location:index.php");            
                        $p_code = "";
                        //$pq->setAdminLogin($username,$password,$p_code);    
                    }
                    else
                    {
                    
        //                $_SESSION['count'] = $_SESSION['count'] + 1;
                        $lblDisplay = "<strong>Erors: </strong><br>"    ;        
                        $lblDisplay.= " - USERNAME OR PASSWORD NOT EXTIS. <br>";
                    }
                    $this->db->closeconnection();

                }
            
        }
                $this->util->send_var('lblDisplay',$lblDisplay);
                $this->util->generate_page(ADMIN_TEMPLATES.'/login.tpl'); 
                
            }
                 
     
    
  }
?>
